import axios from 'axios';

// 订制旅行
function customOrder(token, custom) {
  return new Promise((resolve, reject) => {
    axios.post(`/customOrder`, `token=${token}&phone=${custom.phone}&destination=${custom.destination}&demand=${custom.demand}`).then((result) => {
      if (result.data.ok == 1) resolve();
      else reject();
    });
  });
}

// 预约旅行商品
function submitOrder(form) {
  return new Promise((resolve, reject) => {
    axios
      .post(
        '/submitOrder',
        `uid=${form.uid}&gid=${form.gid}&people=${form.people}&start_time=${form.start_time}&start_place=${form.start_place}&sum=${form.sum}&username=${form.username}&phone=${form.phone}&user_mark=${form.user_mark}`
      )
      .then((result) => {
        if (result.data.ok == 1) resolve();
        else reject();
      });
  });
}

// 获取单个订单信息
function getOrderDtails(oid) {
  return new Promise((resolve, reject) => {
    axios.get(`/getOrderDtails/${oid}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

// 获取单个订制信息
function getCustomDtails(cid) {
  return new Promise((resolve, reject) => {
    axios.get(`/getCustomDtails/${cid}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

export { customOrder, submitOrder, getOrderDtails, getCustomDtails };
